﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Data.SqlClient;
using System.Data;
using DevExpress.XtraEditors;
using prjKQXS_DLL;
using prjKQXS_DLL.Dal;

namespace prjKQXS_Report.Boc
{
    public partial class rptbienbanboc5 : DevExpress.XtraReports.UI.XtraReport
    {
        public rptbienbanboc5()
        {
            InitializeComponent();
        }

        private void rptbienbanboc5_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            Report_DAL report_dal = new Report_DAL();
            lblngay.Text = BienTc.denngay.Day.ToString();
            lblthang.Text = BienTc.denngay.Month.ToString();
            lblnam.Text = BienTc.denngay.Year.ToString();
            dsReports1 = report_dal.reportDungChung(dsReports1);
            dsReports1 = xuly(dsReports1);
        }
        string kyhieu = BienTc.KyHieuVe;
        DateTime ngay = BienTc.denngay;
        public rptbienbanboc5(string kyhieu, DateTime ngayquayso)
        {
            InitializeComponent();

        }
        dsReports ds = new dsReports();
        SqlConnection conn = new SqlConnection(BienTc.connString);
        private dsReports xuly(dsReports ds)
        {
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
            SqlDataAdapter da = null;
            SqlDataAdapter da1 = null;
            da1 = new SqlDataAdapter("Select * from KETQUATT where Convert(Datetime,Ngaymothuong,103) = Convert(Datetime,@Ngay,103)", conn);
            da1.SelectCommand.Parameters.AddWithValue("@Ngay", ngay);
            DataTable dtl = new DataTable();
            da1.Fill(dtl);
            foreach (DataRow rowCB in dtl.Rows)
            {
                DataRow rowC = dsReports1.Hoidongtt.NewRow();
                rowC["Phochutich"] = rowCB["Pchutich"];
                rowC["Congty"] = rowCB["Congty"];
                rowC["Sotuphap"] = rowCB["Sotuphap"];
                rowC["Sotaichinh"] = rowCB["Sotaichinh"];
                rowC["Congantinh"] = rowCB["Congantinh"];
                rowC["Mattrantq"] = rowCB["Mattrantq"];
                rowC["Thanhtrann"] = rowCB["Thanhtrann"];
                rowC["Thuky"] = rowCB["Thuky"];
                dsReports1.Hoidongtt.Rows.Add(rowC);
            }
            da = new SqlDataAdapter("Select * from Ketquaveboc5 Where Kyhieu = @kyhieu", conn);
            da.SelectCommand.Parameters.AddWithValue("@kyhieu", kyhieu);
            DataTable dt = new DataTable();
            da.Fill(dt);
            foreach (DataRow rowCB in dt.Rows)
            {
                DataRow rowC = dsReports1.Ketquaveboc.NewRow();
                rowC["Ngayquayso"] = rowCB["Ngayquayso"];
                rowC["Kyhieu"] = rowCB["Kyhieu"];
                rowC["Giave"] = rowCB["Giave"];
                rowC["gnhat1"] = rowCB["gnhat1"];
                rowC["gnhat2"] = rowCB["gnhat2"];
                rowC["gnhat3"] = rowCB["gnhat3"];
                rowC["gnhat4"] = rowCB["gnhat4"];
                rowC["gnhi1"] = rowCB["gnhi1"];
                rowC["gba1"] = rowCB["gba1"];
                rowC["gtu1"] = rowCB["gtu1"];
                rowC["gtu2"] = rowCB["gtu2"];
                rowC["gtu3"] = rowCB["gtu3"];
                rowC["gtu4"] = rowCB["gtu4"];
                rowC["gtu5"] = rowCB["gtu5"];
                rowC["gtu6"] = rowCB["gtu6"];
                rowC["gtu7"] = rowCB["gtu7"];
                rowC["gtu8"] = rowCB["gtu8"];
                rowC["gtu9"] = rowCB["gtu9"];
                rowC["gtu10"] = rowCB["gtu10"];
                rowC["gtu11"] = rowCB["gtu11"];
                rowC["gtu12"] = rowCB["gtu12"];
                rowC["gtu13"] = rowCB["gtu13"];
                rowC["gtu14"] = rowCB["gtu14"];
                rowC["gtu15"] = rowCB["gtu15"];
                rowC["gtu16"] = rowCB["gtu16"];
                rowC["gnam1"] = rowCB["gnam1"];
                dsReports1.Ketquaveboc.Rows.Add(rowC);
            }
            return ds;
        } 
    }
}
